package co.edu.usbcali.raju.games.chess.model;

import java.util.List;
import java.util.Set;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import com.cgarias.utils.Random;


import co.edu.usbcali.raju.games.chess.server.XBoardAdapter;
import co.edu.usbcali.raju.model.Board;
import co.edu.usbcali.raju.model.Move;
import co.edu.usbcali.raju.model.MoveChooser;

public class RouletteChooser extends MoveChooser {
	
	static Logger logger=Logger.getLogger(MoveChooser.class.getName());
	
	@Override
	public Move chooseMove(Board board, List<Move> moves) {
		logger.debug("Iniciando la evaluación con RouletteChooser");
		evaluate(board, moves,1);
		float add;
		float tot=0;
		if(minEvaluation<=0){
			add=(minEvaluation*-1)+1;
			for (int i = 0; i < evaluations.length; i++) {
				evaluations[i]+=add;
			tot+=evaluations[i];
			}
		}else{
			tot=totalEvaluation;
		}
		float choose=Random.random(tot);
		float acum=0f;
		int con=0;
		for (Float f : evaluations) {
			acum+=f;
			if(choose<acum){
				break;
			}else{
				con++;
			}
		}
		return moves.get(con);
	}

	@Override
	public float complementaryEval(ChessBoard board, Move move, float eval,
			int deep) {
		return eval;
	}


}
